/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package glamourbeautyclinic.service;

import java.awt.Dimension;
import java.awt.Toolkit;
import images.GlamourImage;
import java.awt.Color;
import java.awt.Component;
import static java.awt.Component.CENTER_ALIGNMENT;
import java.awt.Font;
import java.awt.Point;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.RowSorter;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import util.DBConnection;

/**
 *
 * @author anh
 */
public class FrmCate_Service_Hung extends javax.swing.JInternalFrame {

    //Declare for EVERY form
    GlamourImage GI = new GlamourImage();
    //DBConnection dc = new DBConnection();
    DBConnection dc;
    //Declare for CONCRETE form
    Statement stmt;
    ResultSet rs;
    DefaultTableModel serModel;
    DefaultListModel<String> catModel;
    DefaultComboBoxModel<String> catCbxModel;
    boolean isInsertCate = false, isUpdateCat = false, isInsertSer = false, isUpdateSer = false, isView = false;
    String sql, newCatID, newSerID, stateMess;
    int lineCate;

    public FrmCate_Service_Hung(DBConnection dc) {
        //this.setContentPane(new ImageBackgroundPanel(new ImageIcon(GI.getClass().getResource("Frame.png"))));
        initComponents();
        this.dc = dc;
        GI.addIconFor(this);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        // Can be resize height parameter to proper scale
        this.setLocation((screenSize.width - this.getWidth()) / 2 - 200, 10);
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tblSer.getModel());
        tblSer.setRowSorter(sorter);
        tblSer.setComponentPopupMenu(pmnSer);
        catModel = new DefaultListModel<>();
        catCbxModel = new DefaultComboBoxModel<>();
        try {
            stmt = dc.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        beginState();
        lstCat.setCellRenderer(new ListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                JLabel cell = new JLabel();
                cell.setOpaque(true);
                cell.setText(value.toString());
                if (isSelected) {
                    cell.setBackground(lstCat.getSelectionBackground());
                } else {
                    cell.setBackground(lstCat.getBackground());
                }
                try {
                    rs = stmt.executeQuery("select CatName, IsLock from Category");
                    while (rs.next()) {
                        if (rs.getString(1).equalsIgnoreCase(cell.getText())) {
                            if (rs.getBoolean(2)) {
                                cell.setForeground(Color.RED);
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return cell;
            }
        });
        serModel = (DefaultTableModel) tblSer.getModel();
        tblSer.setModel(serModel);
        tblSer.setDefaultRenderer(Object.class, new MyRender());
        tblSer.getModel().addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                if (tblSer.getModel().getRowCount() == 0) {
                    btnSelectAll.setEnabled(false);
                } else {
                    btnSelectAll.setEnabled(true);
                }
                int rowCounter = 0;
                if (e.getColumn() == 0) {
                    boolean flag = false;
                    boolean flag_uncheck = false;

                    for (int i = 0; i < serModel.getRowCount(); i++) {
                        if (serModel.getValueAt(i, 0).equals(true)) {
                            flag = true;
                            rowCounter++;
                        } else {
                            flag_uncheck = true;
                        }
                    }
                    btnSelectAll.setEnabled(flag_uncheck);
                    btnDeselect.setEnabled(flag);
                    //
                    boolean isLock = false;
                    try {
                        rs = stmt.executeQuery("select * from category where CatID='" + txtCatID.getText() + "'");
                        while (rs.next()) {
                            if (rs.getBoolean("isLock")) {
                                isLock = true;
                            }
                        }
                    } catch (Exception t) {
                        t.printStackTrace();
                    }
                    if (rowCounter >= 2 && !isLock) {
                        btnUnlockSer.setEnabled(true);
                        btnLockSer.setEnabled(true);
                        btnPopup.setEnabled(false);
                    }
                }
                int line = tblSer.getSelectedRow();
                if (line == -1 && rowCounter == 0) {
                    //line = tblSer.convertRowIndexToModel(line);
                    btnLockSer.setEnabled(false);
                    btnUnlockSer.setEnabled(false);
                    btnPopup.setEnabled(false);
                    txtSerID.setText("");
                    txtSerName.setText("");
                    txtPrice.setText("");
                    txaDesSer.setText("");
                    cboCat.setSelectedIndex(0);
                }
            }
        });
        tblSer.removeColumn(tblSer.getColumnModel().getColumn(6));
        tblSer.removeColumn(tblSer.getColumnModel().getColumn(5));
        tblSer.removeColumn(tblSer.getColumnModel().getColumn(4));
    }

    //<editor-fold defaultstate="collapsed" desc="Method Group">
    private void beginState() {
        //Category
        lstCat.setEnabled(true);
        btnAddCat.setEnabled(true);
        btnUpdateCat.setEnabled(false);
        btnLockCat.setEnabled(false);
        btnUnlockCat.setEnabled(false);
        txtCatID.setEditable(false);
        txtCatName.setEditable(false);
        txtFac.setEditable(false);
        txaDesCat.setEditable(false);
        lblCatMsg.setText("");
        //Service
        if (tblSer.getModel().getRowCount() == 0) {
            btnSelectAll.setEnabled(false);
        } else {
            btnSelectAll.setEnabled(true);
        }

        btnDeselect.setEnabled(false);
        btnAddSer.setEnabled(true);
        btnUpdateSer.setEnabled(false);
        btnLockSer.setEnabled(false);
        btnUnlockSer.setEnabled(false);
        btnPopup.setEnabled(false);
        txtSerID.setEditable(false);
        txtSerName.setEditable(false);
        if (catCbxModel.getSize() != 0) {
            cboCat.setSelectedIndex(0);
        }
        cboCat.setEnabled(false);
        txtPrice.setEditable(false);
        txaDesSer.setEditable(false);
        lblSerMsg.setText("");
        //---------
        btnSave.setEnabled(false);
        btnCancel.setEnabled(false);
        isInsertCate = false;
        isInsertSer = false;
        isUpdateCat = false;
        isUpdateSer = false;
        //--------------- Add value to category
        updateCatLst_Cbx();
    }

    public void updateCatLst_Cbx() {
        try {
            catModel.clear();
            catModel = new DefaultListModel<>();
            catCbxModel.removeAllElements();
            catCbxModel = new DefaultComboBoxModel<>();
            rs = stmt.executeQuery("select CatName,CatID,IsLock from Category");
            if (!rs.isBeforeFirst()) {
                newCatID = "Cat001";
            } else {
                while (rs.next()) {
                    catModel.addElement(rs.getString(1));
                    if (!rs.getBoolean(3)) {
                        catCbxModel.addElement(rs.getString(1));
                    }
                    if (rs.isLast()) {
                        //Generate a new CatID
                        String temp = rs.getString(2);
                        int tempNum = Integer.parseInt(temp.substring(3)) + 1;
                        temp = String.valueOf(tempNum);
                        newCatID = tempNum < 10 ? "Cat00" + temp
                                : tempNum < 100 ? "Cat0" + temp
                                        : "Cat" + temp;
                    }
                }
                cboCat.setModel(catCbxModel);
                lstCat.setModel(catModel);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //</editor-fold>

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pmnSer = new javax.swing.JPopupMenu();
        mniAddSer = new javax.swing.JMenuItem();
        mniUpdateSer = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mniSelectAll = new javax.swing.JMenuItem();
        mniDeselect = new javax.swing.JMenuItem();
        mniLockSer = new javax.swing.JMenuItem();
        mniUnlockSer = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        mniViewApp = new javax.swing.JMenuItem();
        pnlManagement = new javax.swing.JPanel();
        pnlCategory = new javax.swing.JPanel();
        btnAddCat = new javax.swing.JButton();
        btnUpdateCat = new javax.swing.JButton();
        btnLockCat = new javax.swing.JButton();
        btnUnlockCat = new javax.swing.JButton();
        jspCate = new javax.swing.JScrollPane();
        lstCat = new javax.swing.JList();
        pnlService = new javax.swing.JPanel();
        btnSelectAll = new javax.swing.JButton();
        btnDeselect = new javax.swing.JButton();
        btnAddSer = new javax.swing.JButton();
        btnUpdateSer = new javax.swing.JButton();
        btnLockSer = new javax.swing.JButton();
        btnUnlockSer = new javax.swing.JButton();
        btnPopup = new javax.swing.JButton();
        jspSer = new javax.swing.JScrollPane();
        tblSer = new javax.swing.JTable();
        pnlDetailsCat = new javax.swing.JPanel();
        lblCatName = new javax.swing.JLabel();
        lblRequired1 = new javax.swing.JLabel();
        txtCatName = new javax.swing.JTextField();
        lblFac = new javax.swing.JLabel();
        lblRequired2 = new javax.swing.JLabel();
        txtFac = new javax.swing.JTextField();
        lblDesCat = new javax.swing.JLabel();
        jspDesCat = new javax.swing.JScrollPane();
        txaDesCat = new javax.swing.JTextArea();
        lblCatMsg = new javax.swing.JLabel();
        lblCatID = new javax.swing.JLabel();
        txtCatID = new javax.swing.JTextField();
        pnlDetailsSer = new javax.swing.JPanel();
        lblSerName = new javax.swing.JLabel();
        lblRequired3 = new javax.swing.JLabel();
        txtSerName = new javax.swing.JTextField();
        lblCat = new javax.swing.JLabel();
        lblRequired4 = new javax.swing.JLabel();
        cboCat = new javax.swing.JComboBox();
        lblPrice = new javax.swing.JLabel();
        lblRequired5 = new javax.swing.JLabel();
        txtPrice = new javax.swing.JTextField();
        lblDesSer = new javax.swing.JLabel();
        jspDesSer = new javax.swing.JScrollPane();
        txaDesSer = new javax.swing.JTextArea();
        lblSerMsg = new javax.swing.JLabel();
        lblSerID = new javax.swing.JLabel();
        txtSerID = new javax.swing.JTextField();
        pnlButton = new javax.swing.JPanel();
        btnCancel = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();

        pmnSer.setEnabled(false);
        pmnSer.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                pmnSerPopupMenuWillBecomeVisible(evt);
            }
        });

        mniAddSer.setText("New");
        mniAddSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniAddSerActionPerformed(evt);
            }
        });
        pmnSer.add(mniAddSer);

        mniUpdateSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Update.png"))); // NOI18N
        mniUpdateSer.setText("Update");
        mniUpdateSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniUpdateSerActionPerformed(evt);
            }
        });
        pmnSer.add(mniUpdateSer);
        pmnSer.add(jSeparator1);

        mniSelectAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/SelectAll.png"))); // NOI18N
        mniSelectAll.setText("Select all");
        mniSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniSelectAllActionPerformed(evt);
            }
        });
        pmnSer.add(mniSelectAll);

        mniDeselect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Deselect.png"))); // NOI18N
        mniDeselect.setText("Deselect");
        mniDeselect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniDeselectActionPerformed(evt);
            }
        });
        pmnSer.add(mniDeselect);

        mniLockSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Lock.png"))); // NOI18N
        mniLockSer.setText("Lock");
        mniLockSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniLockSerActionPerformed(evt);
            }
        });
        pmnSer.add(mniLockSer);

        mniUnlockSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Lock.png"))); // NOI18N
        mniUnlockSer.setText("Unlock");
        mniUnlockSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniUnlockSerActionPerformed(evt);
            }
        });
        pmnSer.add(mniUnlockSer);
        pmnSer.add(jSeparator2);

        mniViewApp.setText("View appointment");
        mniViewApp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniViewAppActionPerformed(evt);
            }
        });
        pmnSer.add(mniViewApp);

        setClosable(true);
        setIconifiable(true);
        setTitle("Category and Service Management");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameDeiconified(evt);
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameIconified(evt);
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                formComponentMoved(evt);
            }
        });

        pnlManagement.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Category and Service", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(51, 51, 51))); // NOI18N
        pnlManagement.setOpaque(false);

        pnlCategory.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(113, 147, 183), 1, true), "Category", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 51, 255))); // NOI18N
        pnlCategory.setOpaque(false);

        btnAddCat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Insert.png"))); // NOI18N
        btnAddCat.setToolTipText("Insert new service");
        btnAddCat.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnAddCat.setBorderPainted(false);
        btnAddCat.setContentAreaFilled(false);
        btnAddCat.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAddCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddCatActionPerformed(evt);
            }
        });

        btnUpdateCat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Update.png"))); // NOI18N
        btnUpdateCat.setToolTipText("Update service information");
        btnUpdateCat.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnUpdateCat.setBorderPainted(false);
        btnUpdateCat.setContentAreaFilled(false);
        btnUpdateCat.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnUpdateCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateCatActionPerformed(evt);
            }
        });

        btnLockCat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Lock.png"))); // NOI18N
        btnLockCat.setToolTipText("Lock service");
        btnLockCat.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnLockCat.setBorderPainted(false);
        btnLockCat.setContentAreaFilled(false);
        btnLockCat.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnLockCat.setEnabled(false);
        btnLockCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLockCatActionPerformed(evt);
            }
        });

        btnUnlockCat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unlock.png"))); // NOI18N
        btnUnlockCat.setToolTipText("Unlock service");
        btnUnlockCat.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnUnlockCat.setBorderPainted(false);
        btnUnlockCat.setContentAreaFilled(false);
        btnUnlockCat.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnUnlockCat.setEnabled(false);
        btnUnlockCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnlockCatActionPerformed(evt);
            }
        });

        lstCat.setForeground(new java.awt.Color(0, 102, 51));
        lstCat.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstCat.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstCatValueChanged(evt);
            }
        });
        jspCate.setViewportView(lstCat);

        javax.swing.GroupLayout pnlCategoryLayout = new javax.swing.GroupLayout(pnlCategory);
        pnlCategory.setLayout(pnlCategoryLayout);
        pnlCategoryLayout.setHorizontalGroup(
            pnlCategoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCategoryLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCategoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlCategoryLayout.createSequentialGroup()
                        .addComponent(btnAddCat, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdateCat, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLockCat, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUnlockCat, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 1, Short.MAX_VALUE))
                    .addComponent(jspCate, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))
                .addContainerGap())
        );
        pnlCategoryLayout.setVerticalGroup(
            pnlCategoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCategoryLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlCategoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnAddCat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnUpdateCat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnLockCat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnUnlockCat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jspCate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12))
        );

        pnlService.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(113, 147, 183), 1, true), "Service", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 51, 255))); // NOI18N
        pnlService.setOpaque(false);

        btnSelectAll.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnSelectAll.setForeground(new java.awt.Color(0, 51, 51));
        btnSelectAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/SelectAll.png"))); // NOI18N
        btnSelectAll.setMnemonic('a');
        btnSelectAll.setText("Select all");
        btnSelectAll.setToolTipText("Check all select combo box");
        btnSelectAll.setBorder(null);
        btnSelectAll.setContentAreaFilled(false);
        btnSelectAll.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSelectAll.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnSelectAll.setName(""); // NOI18N
        btnSelectAll.setOpaque(true);
        btnSelectAll.setPreferredSize(new java.awt.Dimension(59, 22));
        btnSelectAll.setRolloverEnabled(false);
        btnSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectAllActionPerformed(evt);
            }
        });

        btnDeselect.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnDeselect.setForeground(new java.awt.Color(0, 51, 51));
        btnDeselect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Deselect.png"))); // NOI18N
        btnDeselect.setMnemonic('e');
        btnDeselect.setText("Deselect");
        btnDeselect.setToolTipText("Uncheck all select combo box");
        btnDeselect.setBorder(null);
        btnDeselect.setContentAreaFilled(false);
        btnDeselect.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnDeselect.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnDeselect.setName(""); // NOI18N
        btnDeselect.setOpaque(true);
        btnDeselect.setPreferredSize(new java.awt.Dimension(59, 22));
        btnDeselect.setRolloverEnabled(false);
        btnDeselect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeselectActionPerformed(evt);
            }
        });

        btnAddSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Insert.png"))); // NOI18N
        btnAddSer.setToolTipText("Insert new service");
        btnAddSer.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnAddSer.setBorderPainted(false);
        btnAddSer.setContentAreaFilled(false);
        btnAddSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSerActionPerformed(evt);
            }
        });

        btnUpdateSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Update.png"))); // NOI18N
        btnUpdateSer.setToolTipText("Update service information");
        btnUpdateSer.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnUpdateSer.setBorderPainted(false);
        btnUpdateSer.setContentAreaFilled(false);
        btnUpdateSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateSerActionPerformed(evt);
            }
        });

        btnLockSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Lock.png"))); // NOI18N
        btnLockSer.setToolTipText("Lock service");
        btnLockSer.setBorderPainted(false);
        btnLockSer.setContentAreaFilled(false);
        btnLockSer.setEnabled(false);
        btnLockSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLockSerActionPerformed(evt);
            }
        });

        btnUnlockSer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unlock.png"))); // NOI18N
        btnUnlockSer.setToolTipText("Unlock service");
        btnUnlockSer.setBorderPainted(false);
        btnUnlockSer.setContentAreaFilled(false);
        btnUnlockSer.setEnabled(false);
        btnUnlockSer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnlockSerActionPerformed(evt);
            }
        });

        btnPopup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/001_25.png"))); // NOI18N
        btnPopup.setToolTipText("Insert new service");
        btnPopup.setBorderPainted(false);
        btnPopup.setContentAreaFilled(false);
        btnPopup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPopupActionPerformed(evt);
            }
        });

        tblSer.setForeground(new java.awt.Color(0, 102, 51));
        tblSer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Select", "Service Name", "Price", "Description", "CatID", "ServiceID", "IsLock"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                true, true, false, false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblSer.setOpaque(false);
        tblSer.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblSer.getTableHeader().setReorderingAllowed(false);
        tblSer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblSerMousePressed(evt);
            }
        });
        jspSer.setViewportView(tblSer);
        if (tblSer.getColumnModel().getColumnCount() > 0) {
            tblSer.getColumnModel().getColumn(0).setPreferredWidth(50);
            tblSer.getColumnModel().getColumn(1).setPreferredWidth(140);
            tblSer.getColumnModel().getColumn(2).setPreferredWidth(50);
            tblSer.getColumnModel().getColumn(3).setPreferredWidth(260);
        }

        javax.swing.GroupLayout pnlServiceLayout = new javax.swing.GroupLayout(pnlService);
        pnlService.setLayout(pnlServiceLayout);
        pnlServiceLayout.setHorizontalGroup(
            pnlServiceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlServiceLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlServiceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlServiceLayout.createSequentialGroup()
                        .addComponent(jspSer)
                        .addContainerGap())
                    .addGroup(pnlServiceLayout.createSequentialGroup()
                        .addComponent(btnSelectAll, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnDeselect, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAddSer, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdateSer, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLockSer, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUnlockSer, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPopup, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16))))
        );
        pnlServiceLayout.setVerticalGroup(
            pnlServiceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlServiceLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlServiceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlServiceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnSelectAll, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnDeselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnAddSer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnUpdateSer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnLockSer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnUnlockSer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnPopup, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jspSer, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43))
        );

        javax.swing.GroupLayout pnlManagementLayout = new javax.swing.GroupLayout(pnlManagement);
        pnlManagement.setLayout(pnlManagementLayout);
        pnlManagementLayout.setHorizontalGroup(
            pnlManagementLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlManagementLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlCategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlService, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10))
        );
        pnlManagementLayout.setVerticalGroup(
            pnlManagementLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlManagementLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlManagementLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlCategory, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlService, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
        );

        pnlDetailsCat.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Category details infomation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(51, 51, 51))); // NOI18N
        pnlDetailsCat.setOpaque(false);

        lblCatName.setDisplayedMnemonic('n');
        lblCatName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblCatName.setForeground(new java.awt.Color(0, 51, 255));
        lblCatName.setText("Categoty Name");
        lblCatName.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired1.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired1.setText("(*)");
        lblRequired1.setPreferredSize(new java.awt.Dimension(38, 20));

        txtCatName.setForeground(new java.awt.Color(0, 102, 51));
        txtCatName.setPreferredSize(new java.awt.Dimension(56, 20));

        lblFac.setDisplayedMnemonic('r');
        lblFac.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblFac.setForeground(new java.awt.Color(0, 51, 255));
        lblFac.setText("No of Facilities");
        lblFac.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired2.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired2.setText("(*)");
        lblRequired2.setPreferredSize(new java.awt.Dimension(38, 20));

        txtFac.setForeground(new java.awt.Color(0, 102, 51));
        txtFac.setPreferredSize(new java.awt.Dimension(56, 20));

        lblDesCat.setDisplayedMnemonic('r');
        lblDesCat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblDesCat.setForeground(new java.awt.Color(0, 51, 255));
        lblDesCat.setText("Description");
        lblDesCat.setPreferredSize(new java.awt.Dimension(38, 20));

        txaDesCat.setColumns(20);
        txaDesCat.setForeground(new java.awt.Color(0, 102, 51));
        txaDesCat.setRows(5);
        jspDesCat.setViewportView(txaDesCat);

        lblCatMsg.setForeground(new java.awt.Color(255, 51, 51));
        lblCatMsg.setPreferredSize(new java.awt.Dimension(38, 20));

        lblCatID.setDisplayedMnemonic('n');
        lblCatID.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblCatID.setForeground(new java.awt.Color(0, 51, 255));
        lblCatID.setText("Categoty ID");
        lblCatID.setPreferredSize(new java.awt.Dimension(38, 20));

        txtCatID.setForeground(new java.awt.Color(0, 102, 51));
        txtCatID.setPreferredSize(new java.awt.Dimension(56, 20));

        javax.swing.GroupLayout pnlDetailsCatLayout = new javax.swing.GroupLayout(pnlDetailsCat);
        pnlDetailsCat.setLayout(pnlDetailsCatLayout);
        pnlDetailsCatLayout.setHorizontalGroup(
            pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailsCatLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lblCatMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlDetailsCatLayout.createSequentialGroup()
                            .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lblFac, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblDesCat, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblCatName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblRequired1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblRequired2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtFac, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtCatName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jspDesCat, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)))
                        .addGroup(pnlDetailsCatLayout.createSequentialGroup()
                            .addComponent(lblCatID, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(27, 27, 27)
                            .addComponent(txtCatID, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlDetailsCatLayout.setVerticalGroup(
            pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDetailsCatLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblCatID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCatID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblCatName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblRequired1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCatName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblRequired2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtFac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlDetailsCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDesCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jspDesCat, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCatMsg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30))
        );

        pnlDetailsSer.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Service details infomation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(51, 51, 51))); // NOI18N
        pnlDetailsSer.setOpaque(false);

        lblSerName.setDisplayedMnemonic('n');
        lblSerName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblSerName.setForeground(new java.awt.Color(0, 51, 255));
        lblSerName.setText("Service Name");
        lblSerName.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired3.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired3.setText("(*)");
        lblRequired3.setPreferredSize(new java.awt.Dimension(38, 20));

        txtSerName.setForeground(new java.awt.Color(0, 102, 51));
        txtSerName.setPreferredSize(new java.awt.Dimension(56, 20));

        lblCat.setDisplayedMnemonic('r');
        lblCat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblCat.setForeground(new java.awt.Color(0, 51, 255));
        lblCat.setText("Category");
        lblCat.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired4.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired4.setText("(*)");
        lblRequired4.setPreferredSize(new java.awt.Dimension(38, 20));

        cboCat.setForeground(new java.awt.Color(0, 102, 51));
        cboCat.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Hair", "Item 2", "Item 3", "Item 4" }));
        cboCat.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboCatItemStateChanged(evt);
            }
        });

        lblPrice.setDisplayedMnemonic('r');
        lblPrice.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblPrice.setForeground(new java.awt.Color(0, 51, 255));
        lblPrice.setText("Price");
        lblPrice.setPreferredSize(new java.awt.Dimension(38, 20));

        lblRequired5.setForeground(new java.awt.Color(255, 51, 51));
        lblRequired5.setText("(*)");
        lblRequired5.setPreferredSize(new java.awt.Dimension(38, 20));

        txtPrice.setForeground(new java.awt.Color(0, 102, 51));
        txtPrice.setPreferredSize(new java.awt.Dimension(56, 20));

        lblDesSer.setDisplayedMnemonic('r');
        lblDesSer.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblDesSer.setForeground(new java.awt.Color(0, 51, 255));
        lblDesSer.setText("Description");
        lblDesSer.setPreferredSize(new java.awt.Dimension(38, 20));

        txaDesSer.setColumns(20);
        txaDesSer.setForeground(new java.awt.Color(0, 102, 51));
        txaDesSer.setRows(5);
        jspDesSer.setViewportView(txaDesSer);

        lblSerMsg.setForeground(new java.awt.Color(255, 51, 51));
        lblSerMsg.setPreferredSize(new java.awt.Dimension(38, 20));

        lblSerID.setDisplayedMnemonic('n');
        lblSerID.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblSerID.setForeground(new java.awt.Color(0, 51, 255));
        lblSerID.setText("Service ID");
        lblSerID.setPreferredSize(new java.awt.Dimension(38, 20));

        txtSerID.setForeground(new java.awt.Color(0, 102, 51));
        txtSerID.setPreferredSize(new java.awt.Dimension(56, 20));

        javax.swing.GroupLayout pnlDetailsSerLayout = new javax.swing.GroupLayout(pnlDetailsSer);
        pnlDetailsSer.setLayout(pnlDetailsSerLayout);
        pnlDetailsSerLayout.setHorizontalGroup(
            pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDetailsSerLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDetailsSerLayout.createSequentialGroup()
                        .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblDesSer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblCat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblSerName, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblRequired5, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblRequired3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lblRequired4, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtSerName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cboCat, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtPrice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jspDesSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlDetailsSerLayout.createSequentialGroup()
                        .addComponent(lblSerID, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(txtSerID, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDetailsSerLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lblSerMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlDetailsSerLayout.setVerticalGroup(
            pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDetailsSerLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSerID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtSerID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDetailsSerLayout.createSequentialGroup()
                        .addComponent(lblSerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblRequired4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblDesSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlDetailsSerLayout.createSequentialGroup()
                        .addComponent(txtSerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cboCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlDetailsSerLayout.createSequentialGroup()
                        .addComponent(lblRequired3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addGroup(pnlDetailsSerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblRequired5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jspDesSer, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblSerMsg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33))
        );

        pnlButton.setOpaque(false);

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Cancel.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        pnlButton.add(btnCancel);

        btnSave.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnSave.setForeground(new java.awt.Color(0, 51, 51));
        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Save.png"))); // NOI18N
        btnSave.setMnemonic('x');
        btnSave.setText("Save");
        btnSave.setToolTipText("Save to database");
        btnSave.setBorder(null);
        btnSave.setContentAreaFilled(false);
        btnSave.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSave.setEnabled(false);
        btnSave.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnSave.setName(""); // NOI18N
        btnSave.setOpaque(true);
        btnSave.setPreferredSize(new java.awt.Dimension(59, 22));
        btnSave.setRolloverEnabled(false);
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });
        pnlButton.add(btnSave);

        btnExit.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExit.setForeground(new java.awt.Color(0, 51, 51));
        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quit.png"))); // NOI18N
        btnExit.setMnemonic('x');
        btnExit.setText("Exit");
        btnExit.setToolTipText("Close window");
        btnExit.setBorder(null);
        btnExit.setContentAreaFilled(false);
        btnExit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnExit.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnExit.setName(""); // NOI18N
        btnExit.setOpaque(true);
        btnExit.setPreferredSize(new java.awt.Dimension(59, 22));
        btnExit.setRolloverEnabled(false);
        pnlButton.add(btnExit);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(pnlManagement, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(pnlDetailsCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(pnlDetailsSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(pnlButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pnlManagement, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlDetailsCat, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlDetailsSer, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mniViewAppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniViewAppActionPerformed
        btnPopupActionPerformed(evt);
    }//GEN-LAST:event_mniViewAppActionPerformed

    private void btnPopupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPopupActionPerformed
        JDesktopPane desk = getDesktopPane();
        int line = tblSer.getSelectedRow();
        line = tblSer.convertRowIndexToModel(line);

        if (isView) {
            JInternalFrame[] j = desk.getAllFrames();
            for (int i = 0; i < j.length; i++) {
                if ("SerApp".equals(j[i].getName())) {
                    j[i].setVisible(false);
                    j[i].dispose();
                }
            }
            btnPopup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/001_25.png")));
            isView = false;
        } else {
            JInternalFrame dlgRelApp = new FrmSerApp(dc, this, (String) serModel.getValueAt(line, 1), (String) serModel.getValueAt(line, 5));
            desk.add(dlgRelApp);
            btnPopup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/001_27.png")));
            isView = true;
            dlgRelApp.setVisible(true);
        }


    }//GEN-LAST:event_btnPopupActionPerformed

    private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("SerApp".equals(j[i].getName())) {
                j[i].setLocation(this.getX() + this.getWidth() + 10, this.getY());
            }
        }

    }//GEN-LAST:event_formComponentMoved

    private void tblSerMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblSerMousePressed
        int line = tblSer.getSelectedRow();
        if (line != -1) {
            line = tblSer.convertRowIndexToModel(line);
            btnPopup.setEnabled(true);
            if (isView) {
                JDesktopPane desk = getDesktopPane();
                JInternalFrame[] j = desk.getAllFrames();
                for (int i = 0; i < j.length; i++) {
                    if ("SerApp".equals(j[i].getName())) {
                        j[i].dispose();
                    }
                }
                JInternalFrame dlgRelApp = new FrmSerApp(dc, this, (String) serModel.getValueAt(line, 1), (String) serModel.getValueAt(line, 5));
                desk.add(dlgRelApp);
                dlgRelApp.setVisible(true);
            }
            if (!isInsertCate && !isInsertSer && !isUpdateCat && !isUpdateSer) {
                try {
                    rs = stmt.executeQuery("select * from category");
                    while (rs.next()) {
                        if (rs.getString("CatName").equalsIgnoreCase((String) lstCat.getSelectedValue())) {
                            if (rs.getBoolean("isLock")) {
                                btnLockSer.setEnabled(false);
                                btnUnlockSer.setEnabled(false);
                                btnUpdateSer.setEnabled(false);

                            } else {
                                btnLockSer.setEnabled(!serModel.getValueAt(line, 6).equals(true));
                                btnUnlockSer.setEnabled(serModel.getValueAt(line, 6).equals(true));
                                btnUpdateSer.setEnabled(!serModel.getValueAt(line, 6).equals(true));
                            }
                            break;
                        }

                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

                //Add values to fields;
                txtSerID.setText((String) serModel.getValueAt(line, 5));
                txtSerName.setText((String) serModel.getValueAt(line, 1));
                try {
                    rs = stmt.executeQuery("select CatName,CatID from category");
                    while (rs.next()) {
                        if (rs.getString(2).equals(serModel.getValueAt(line, 4))) {
                            cboCat.setSelectedItem(rs.getString(1));
                            break;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                txtPrice.setText(String.valueOf(serModel.getValueAt(line, 2)));
                txaDesSer.setText((String) serModel.getValueAt(line, 3));
            } else {
                btnLockSer.setEnabled(false);
                btnUnlockSer.setEnabled(false);
                btnUpdateSer.setEnabled(false);
            }
            //Change select to row selected
            if (tblSer.getSelectedColumn() != 0) {
                for (int i = 0; i < serModel.getRowCount(); i++) {
                    serModel.setValueAt(false, i, 0);
                }
                serModel.setValueAt(true, line, 0);
            }
            //

        } else {
            //
        }
    }//GEN-LAST:event_tblSerMousePressed

    private void formInternalFrameIconified(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameIconified
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("SerApp".equals(j[i].getName())) {
                j[i].setVisible(false);
            }
        }
    }//GEN-LAST:event_formInternalFrameIconified

    private void formInternalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameDeiconified
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("SerApp".equals(j[i].getName())) {
                j[i].setVisible(true);
            }
        }
    }//GEN-LAST:event_formInternalFrameDeiconified

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        JDesktopPane desk = getDesktopPane();
        JInternalFrame[] j = desk.getAllFrames();

        for (int i = 0; i < j.length; i++) {
            if ("SerApp".equals(j[i].getName())) {
                j[i].dispose();
            }
        }
    }//GEN-LAST:event_formInternalFrameClosing
    public void offONButton() {
        btnAddCat.setEnabled(false);
        btnAddSer.setEnabled(false);
        btnUpdateCat.setEnabled(false);
        btnUpdateSer.setEnabled(false);
    }

    public void insertUpdateState() {
        btnAddCat.setEnabled(false);
        btnAddSer.setEnabled(false);
        btnUnlockCat.setEnabled(false);
        btnUnlockSer.setEnabled(false);
        btnUpdateCat.setEnabled(false);
        btnUpdateSer.setEnabled(false);
        btnLockCat.setEnabled(false);
        btnLockSer.setEnabled(false);
        btnCancel.setEnabled(true);
        btnSave.setEnabled(true);
    }

    public void openFieldCat(String s) {
        txtCatName.setEditable(true);
        txtFac.setEditable(true);
        txaDesCat.setEditable(true);
        if (s.equalsIgnoreCase("insert")) {
            txtCatID.setText(newCatID);
            txtCatName.setText("");
            txtFac.setText("");
            txaDesCat.setText("");
        }
    }

    public void openFieldSer(String s) {
        txtSerName.setEditable(true);
        txtPrice.setEditable(true);
        txaDesSer.setEditable(true);
        if (s.equalsIgnoreCase("insert")) {
            txtSerID.setText(newSerID);
            cboCat.setEnabled(true);
            txtSerName.setText("");
            txtPrice.setText("");
            txaDesSer.setText("");
        }
    }
    private void btnAddCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddCatActionPerformed
        isInsertCate = true;
        insertUpdateState();
        openFieldCat("insert");
    }//GEN-LAST:event_btnAddCatActionPerformed

    private void btnUpdateCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateCatActionPerformed
        isUpdateCat = true;
        insertUpdateState();
        openFieldCat("");
    }//GEN-LAST:event_btnUpdateCatActionPerformed

    private void btnLockCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLockCatActionPerformed
        int ans = JOptionPane.showConfirmDialog(this, "Do you want to lock this Category.\nThis will also lock its services", "Warning", JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            sql = "Update Category set IsLock=1 where CatID='" + txtCatID.getText() + "'";
            try {
                stmt.executeUpdate(sql);
                stmt.executeUpdate("Update Services set isLock=1 where CatID='" + txtCatID.getText() + "'");
                int lineCat = lstCat.getSelectedIndex();
                beginState();
                lstCat.setSelectedIndex(lineCat);
                btnAddSer.setEnabled(false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {

        }

    }//GEN-LAST:event_btnLockCatActionPerformed

    private void btnUnlockCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnlockCatActionPerformed
        sql = "Update Category set IsLock=0 where CatID='" + txtCatID.getText() + "'";
        try {
            int temp = lstCat.getSelectedIndex();
            stmt.executeUpdate(sql);
            int lineCat = lstCat.getSelectedIndex();
            beginState();
            lstCat.setSelectedIndex(lineCat);
            lstCat.setSelectedIndex(temp);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnUnlockCatActionPerformed

    private void lstCatValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstCatValueChanged
        int line = lstCat.getSelectedIndex();
        if (line != -1) {
            try {
                rs = stmt.executeQuery("Select * from Category");
                String CatID = "";
                while (rs.next()) {
                    // Find category in Database
                    if (rs.getString(2).equalsIgnoreCase(catModel.get(line))) {
                        CatID = rs.getString(1);
                        if (isInsertCate || isInsertSer || isUpdateCat || isUpdateSer) {
                            insertUpdateState();
                        } else {
                            if (rs.getBoolean("IsLock")) {
                                btnUnlockCat.setEnabled(true);
                                btnLockCat.setEnabled(false);
                                btnUpdateCat.setEnabled(false);
                                btnAddSer.setEnabled(false);
                            } else {
                                btnUnlockCat.setEnabled(false);
                                btnLockCat.setEnabled(true);
                                btnUpdateCat.setEnabled(true);
                                btnAddSer.setEnabled(true);
                            }

                            //Add data to fields 
                            txtCatID.setText(rs.getString(1));
                            txtCatName.setText(rs.getString(2));
                            txaDesCat.setText(rs.getString(3));
                            txtFac.setText(String.valueOf(rs.getInt(4)));
                        }
                        break;
                    }
                }
                //Add Data to Service Table with this Category
                tblSer.getSelectionModel().clearSelection();
                serModel.setRowCount(0);
                rs = stmt.executeQuery("select * from Services where CatID='" + CatID + "'");
                while (rs.next()) {
                    serModel.addRow(new Object[]{false, rs.getString(2)//Service Name
                        , rs.getDouble(4) // Price
                        , rs.getString(5) // Desc
                        , rs.getString(3) // CatID
                        , rs.getString(1) //SerID
                        , rs.getBoolean(6) // IsLock
                    });
                }
                tblSer.setModel(serModel);
            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {
            btnUpdateCat.setEnabled(false);
            btnUnlockCat.setEnabled(false);
            btnLockCat.setEnabled(false);
            txtCatID.setText("");
            txtCatName.setText("");
            txaDesCat.setText("");
            txtFac.setText("");

        }
    }//GEN-LAST:event_lstCatValueChanged

    private void btnAddSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSerActionPerformed
        isInsertSer = true;
        insertUpdateState();
        cboCatItemStateChanged(null);
        openFieldSer("insert");
        lstCat.setEnabled(false);
    }//GEN-LAST:event_btnAddSerActionPerformed

    private void btnUpdateSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateSerActionPerformed
        isUpdateSer = true;
        insertUpdateState();
        openFieldSer("");
        lineCate = lstCat.getSelectedIndex();
        lstCat.setEnabled(false);
    }//GEN-LAST:event_btnUpdateSerActionPerformed

    private void btnLockSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLockSerActionPerformed
        int ans = JOptionPane.showConfirmDialog(this, "Do you want to lock services?", "Warning", JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            ArrayList selectedLine = new ArrayList();
            for (int i = 0; i < serModel.getRowCount(); i++) {
                if (serModel.getValueAt(i, 0).equals(true)) {
                    selectedLine.add(i);
                }
            }
            for (int i = 0; i < selectedLine.size(); i++) {
                sql = "Update services set isLock=1 where ServiceID='" + serModel.getValueAt((int) selectedLine.get(i), 5) + "'";
                try {
                    stmt.executeUpdate(sql);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            int lineCat = lstCat.getSelectedIndex();
            beginState();
            lstCat.setSelectedIndex(lineCat);
        } else {
            return;
        }


    }//GEN-LAST:event_btnLockSerActionPerformed

    private void btnUnlockSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnlockSerActionPerformed
        ArrayList selectedLine = new ArrayList();
        for (int i = 0; i < serModel.getRowCount(); i++) {
            if (serModel.getValueAt(i, 0).equals(true)) {
                selectedLine.add(i);
            }
        }
        for (int i = 0; i < selectedLine.size(); i++) {
            sql = "Update services set isLock=0 where ServiceID='" + serModel.getValueAt((int) selectedLine.get(i), 5) + "'";
            try {
                stmt.executeUpdate(sql);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        int lineCat = lstCat.getSelectedIndex();
        beginState();
        lstCat.setSelectedIndex(lineCat);
    }//GEN-LAST:event_btnUnlockSerActionPerformed
    public String checkFieldCate() {
        String cateName = txtCatName.getText();
        String Sfac = txtFac.getText();
        if (cateName.equals("")) {
            txtCatName.grabFocus();
            return "Category Name cannot be blank";
        } else {
            if (cateName.length() > 50) {
                txtCatName.grabFocus();
                return "Category Name cannot have more than 50 characters";
            } else {
                try {
                    if (isInsertCate) {
                        rs = stmt.executeQuery("select * from category");
                        while (rs.next()) {
                            if (rs.getString("catName").equalsIgnoreCase(cateName)) {
                                txtCatName.grabFocus();
                                return "This Category has already existed";
                            }
                        }
                    }
                    if (isUpdateCat) {
                        if (!txtCatName.getText().equalsIgnoreCase((String) lstCat.getSelectedValue())) {
                            rs = stmt.executeQuery("select * from category");
                            while (rs.next()) {
                                if (rs.getString("catName").equalsIgnoreCase(cateName)) {
                                    txtCatName.grabFocus();
                                    return "This Category has already existed";
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
        try {
            if (Sfac.equals("")) {
                txtFac.grabFocus();
                return "Facilities cannot be blank";
            }
            int fac = Integer.parseInt(Sfac);
            if (fac < 0) {
                txtFac.grabFocus();
                return "Facilities must be greater than 0";
            } else {
                return "";
            }
        } catch (Exception e) {
            txtFac.grabFocus();
            return "Facilities must be numberic";
        }
    }

    public String checkFieldSer() {
        //String SerID = txtSerID.getText();
        String SerName = txtSerName.getText();
        String priceStr = txtPrice.getText();
        if (SerName.equals("")) {
            txtSerName.grabFocus();
            return "Service Name cannot be blank";
        } else {
            if (SerName.length() > 50) {
                txtSerName.grabFocus();
                return "Service Name cannot have more than 50 characters";
            } else {
                try {
                    if (isInsertSer) {
                        rs = stmt.executeQuery("select * from services");
                        while (rs.next()) {
                            if (rs.getString("serviceName").equalsIgnoreCase(SerName)) {
                                txtSerName.grabFocus();
                                return "This service name has already existed";
                            }
                        }
                    }
                    if (isUpdateSer) {
                        rs = stmt.executeQuery("select ServiceName from services where ServiceID='" + txtSerID.getText() + "'");
                        rs.first();
                        if (!txtSerName.getText().equalsIgnoreCase(rs.getString(1))) {
                            rs = stmt.executeQuery("select * from services");
                            while (rs.next()) {
                                if (rs.getString("serviceName").equalsIgnoreCase(SerName)) {
                                    txtSerName.grabFocus();
                                    return "This service name has already existed";
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (txaDesSer.getText().length() > 200) {
            txaDesSer.grabFocus();
            return "Description cannot have more than 200 characters";
        }
        try {
            if (priceStr.equals("")) {
                txtPrice.grabFocus();
                return "Price cannot be blank";
            }
            double price = Double.parseDouble(priceStr);
            if (price < 0) {
                txtPrice.grabFocus();
                return "Price must be greater than 0";
            } else {
                return "";
            }
        } catch (Exception e) {
            txtPrice.grabFocus();
            return "Price must be numberic";
        }
    }

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        String error;
        boolean flag = false;
        if (isInsertCate || isUpdateCat) {
            error = checkFieldCate();
            if (error.equals("")) {
                String CatID = txtCatID.getText();
                String CatName = txtCatName.getText();
                String Desc = txaDesCat.getText();
                int Fac = Integer.parseInt(txtFac.getText());
                if (isInsertCate) {
                    sql = "Insert Into Category values ('"
                            + CatID + "','"
                            + CatName + "','"
                            + Desc + "',"
                            + Fac + ",1)";
                }
                if (isUpdateCat) {
                    sql = "Update Category set CatName='" + CatName + "', [Desc]='" + Desc + "', Facilities="
                            + Fac + " where CatID='" + CatID + "'";
                }
            } else {
                lblCatMsg.setText(error);
                return;
            }
        }
        if (isInsertSer || isUpdateSer) {
            error = checkFieldSer();
            flag = true;
            if (error.equals("")) {
                String SerID = txtSerID.getText();
                String SerName = txtSerName.getText();
                String CatID = SerID.substring(0, 6);
                double Price = Double.parseDouble(txtPrice.getText());
                String Desc = txaDesSer.getText();
                if (isInsertSer) {
                    sql = "Insert into Services values ('" + SerID + "','"
                            + SerName + "','"
                            + CatID + "',"
                            + Price + ",'"
                            + Desc + "',0)";
                }
                if (isUpdateSer) {
                    sql = "Update Services set ServiceName='"
                            + SerName + "', Price=" + Price + ", [Desc]='" + Desc + "' where ServiceID='" + SerID + "'";
                }
            } else {
                lblSerMsg.setText(error);
                return;
            }
        }

        try {
            //System.out.println(sql);
            stmt.executeUpdate(sql);
            String temp_cate = (String) cboCat.getSelectedItem();
            beginState();
            if (flag) {
                for (int i = 0; i < catModel.getSize(); i++) {
                    if (catModel.get(i).equals(temp_cate)) {
                        lstCat.setSelectedIndex(i);
                        break;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        int line = lstCat.getSelectedIndex();
        beginState();
        lstCat.setSelectedIndex(line);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void cboCatItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCatItemStateChanged
        if (isInsertSer) {
            sql = "Select CatName,ServiceID from vw_cate_services where CatName='" + catCbxModel.getSelectedItem() + "'";
            try {
                rs = stmt.executeQuery(sql);
                if (!rs.isBeforeFirst()) {
                    rs = stmt.executeQuery("Select CatID,CatName from category");
                    while (rs.next()) {
                        if (rs.getString(2).equalsIgnoreCase((String) catCbxModel.getSelectedItem())) {
                            newSerID = rs.getString(1) + ".01";
                        }
                    }
                } else {
                    rs.last();
                    String temp = rs.getString(2);
                    int tempNum = Integer.parseInt(temp.substring(8)) + 1;
                    temp = temp.substring(0, 7);
                    newSerID = tempNum < 10 ? temp + "0" + tempNum : temp + temp;
                }
                txtSerID.setText(newSerID);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }//GEN-LAST:event_cboCatItemStateChanged

    private void btnSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectAllActionPerformed
        for (int i = 0; i < tblSer.getModel().getRowCount(); i++) {
            serModel.setValueAt(true, i, 0);
        }
    }//GEN-LAST:event_btnSelectAllActionPerformed

    private void btnDeselectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeselectActionPerformed
        for (int i = 0; i < tblSer.getModel().getRowCount(); i++) {
            serModel.setValueAt(false, i, 0);
        }
    }//GEN-LAST:event_btnDeselectActionPerformed

    private void mniAddSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniAddSerActionPerformed
        if (mniAddSer.isEnabled()) {
            btnAddSerActionPerformed(evt);
        }
    }//GEN-LAST:event_mniAddSerActionPerformed

    private void pmnSerPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_pmnSerPopupMenuWillBecomeVisible
        mniAddSer.setEnabled(btnAddSer.isEnabled());
        mniUpdateSer.setEnabled(btnUpdateSer.isEnabled());
        mniSelectAll.setEnabled(btnSelectAll.isEnabled());
        mniDeselect.setEnabled(btnDeselect.isEnabled());
        mniLockSer.setEnabled(btnLockSer.isEnabled());
        mniUnlockSer.setEnabled(btnUnlockSer.isEnabled());
        mniViewApp.setEnabled(btnPopup.isEnabled());
    }//GEN-LAST:event_pmnSerPopupMenuWillBecomeVisible

    private void mniUpdateSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniUpdateSerActionPerformed
        btnUpdateSerActionPerformed(evt);
    }//GEN-LAST:event_mniUpdateSerActionPerformed

    private void mniSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniSelectAllActionPerformed
        btnSelectAllActionPerformed(evt);
    }//GEN-LAST:event_mniSelectAllActionPerformed

    private void mniDeselectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniDeselectActionPerformed
        btnDeselectActionPerformed(evt);
    }//GEN-LAST:event_mniDeselectActionPerformed

    private void mniLockSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniLockSerActionPerformed
        btnLockSerActionPerformed(evt);
    }//GEN-LAST:event_mniLockSerActionPerformed

    private void mniUnlockSerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniUnlockSerActionPerformed
        btnUnlockSerActionPerformed(evt);
    }//GEN-LAST:event_mniUnlockSerActionPerformed

//<editor-fold defaultstate="collapsed" desc="Variables">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddCat;
    private javax.swing.JButton btnAddSer;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDeselect;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnLockCat;
    private javax.swing.JButton btnLockSer;
    private javax.swing.JButton btnPopup;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSelectAll;
    private javax.swing.JButton btnUnlockCat;
    private javax.swing.JButton btnUnlockSer;
    private javax.swing.JButton btnUpdateCat;
    private javax.swing.JButton btnUpdateSer;
    private javax.swing.JComboBox cboCat;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JScrollPane jspCate;
    private javax.swing.JScrollPane jspDesCat;
    private javax.swing.JScrollPane jspDesSer;
    private javax.swing.JScrollPane jspSer;
    private javax.swing.JLabel lblCat;
    private javax.swing.JLabel lblCatID;
    private javax.swing.JLabel lblCatMsg;
    private javax.swing.JLabel lblCatName;
    private javax.swing.JLabel lblDesCat;
    private javax.swing.JLabel lblDesSer;
    private javax.swing.JLabel lblFac;
    private javax.swing.JLabel lblPrice;
    private javax.swing.JLabel lblRequired1;
    private javax.swing.JLabel lblRequired2;
    private javax.swing.JLabel lblRequired3;
    private javax.swing.JLabel lblRequired4;
    private javax.swing.JLabel lblRequired5;
    private javax.swing.JLabel lblSerID;
    private javax.swing.JLabel lblSerMsg;
    private javax.swing.JLabel lblSerName;
    private javax.swing.JList lstCat;
    private javax.swing.JMenuItem mniAddSer;
    private javax.swing.JMenuItem mniDeselect;
    private javax.swing.JMenuItem mniLockSer;
    private javax.swing.JMenuItem mniSelectAll;
    private javax.swing.JMenuItem mniUnlockSer;
    private javax.swing.JMenuItem mniUpdateSer;
    private javax.swing.JMenuItem mniViewApp;
    private javax.swing.JPopupMenu pmnSer;
    private javax.swing.JPanel pnlButton;
    private javax.swing.JPanel pnlCategory;
    private javax.swing.JPanel pnlDetailsCat;
    private javax.swing.JPanel pnlDetailsSer;
    private javax.swing.JPanel pnlManagement;
    private javax.swing.JPanel pnlService;
    private javax.swing.JTable tblSer;
    private javax.swing.JTextArea txaDesCat;
    private javax.swing.JTextArea txaDesSer;
    private javax.swing.JTextField txtCatID;
    private javax.swing.JTextField txtCatName;
    private javax.swing.JTextField txtFac;
    private javax.swing.JTextField txtPrice;
    private javax.swing.JTextField txtSerID;
    private javax.swing.JTextField txtSerName;
    // End of variables declaration//GEN-END:variables
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Renderer">

    class MyRender implements TableCellRenderer {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            row = table.convertRowIndexToModel(row);
            JTextField editor = new JTextField();
            editor.setBorder(null);
            editor.setText(value.toString());
            editor.setHorizontalAlignment((int) CENTER_ALIGNMENT);
            if (isSelected) {
                if (table.getModel().getValueAt(row, 6).equals(true)) {
                    editor.setBackground(new Color(0, 51, 255));
                    editor.setForeground(Color.WHITE);
                    editor.setFont(getFont().deriveFont(Font.BOLD));
                } else {
                    editor.setBackground(table.getSelectionBackground());
                }

            } else {
                if (table.getModel().getValueAt(row, 6).equals(true)) {

                    editor.setForeground(Color.BLACK);
                    editor.setBackground(Color.LIGHT_GRAY);
                } else {
                    editor.setForeground(Color.BLACK);
                }
            }
            return editor;
        }
    }
//</editor-fold>
}
